package entities;

import fields.Fleet;
import fields.LaborCamp;
import fields.Ownable;
import gstd.Field;
import gstd.InventoryAbs;

import java.util.ArrayList;

public class Inventory extends InventoryAbs {
	private ArrayList<Field> ownedFields = new ArrayList<Field>();

	public Inventory(int balance) {
		super(balance);
	}

	public int getNumberOfFleets() {
		int numberOfFleets = 0;

		// Checks how many fleets there are in the list of fields in the
		// inventory
		for (Field field : ownedFields) {
			if (field.getClass() == Fleet.class) {
				numberOfFleets++;
			}
		}
		return numberOfFleets;
	}

	public int getNumberOfLaborCamps() {
		int numberOfLaborCamp = 0;

		// Checks how many fleets there are in the list of fields in the
		// inventory
		for (int i = 0; i < ownedFields.size(); i++) {
			if (getField(i).getClass().equals(LaborCamp.class)) {
				numberOfLaborCamp += 1;
			}
		}
		return numberOfLaborCamp;
	}

	// All the prices of the areas together
	public int getTotalAssets() {
		int sum = 0;

		// Finds all the fields in the inventory and puts the price together
		for (int i = 0; i < ownedFields.size(); i++) {
			sum += ((Ownable) getField(i)).getPrice();
		}
		sum += balance;
		return sum;
	}

	public Field getField(int numberInArray) {
		return (Field) ownedFields.get(numberInArray);
	}

	public ArrayList<Field> getOwnedFields() {
		return ownedFields;
	}

	public void addField(Field field) {
		ownedFields.add(field);
	}

	public void removeField(int index) {
		ownedFields.remove(index);
	}

	public void removeAllFields() {
		ownedFields.clear();
	}

	public void reset() {
		for (Field field : getOwnedFields()) {
			((Ownable) field).setOwner(null);
		}
		ownedFields.clear();
	}
}
